<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:composite="http://java.sun.com/jsf/composite"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:h ="http://java.sun.com/jsf/html"
        xmlns:c="http://java.sun.com/jsp/jstl/core"
        xmlns:f="http://java.sun.com/jsf/core">

    <!-- INTERFACE -->
  <composite:interface>
      <composite:attribute name="loginManager" required="true"/>
  </composite:interface>

  <!-- IMPLEMENTATION -->
  <composite:implementation>

    <h:form id="sendeRegistrierung">
            <div>
                <h:selectBooleanCheckbox id="showPersonalData" immediate="true" value="#{cc.attrs.loginManager.personalData}"
                                     valueChangeListener="#{cc.attrs.loginManager.displayChanged}" onclick="this.form.submit()"/>

                <h:outputLabel value="#{msg.personal_data}" for="showPersonalData"/>
            </div>
            <c:if test="#{cc.attrs.loginManager.personalData}">
            <h3>#{msg.personal_data}</h3>
            <div class="formblock">
                <fieldset>
                    <div>
                        <h:outputLabel styleClass="Float" for="firstname" value="#{msg.firstname}"/>
                        <h:inputText id="firstname" value="#{cc.attrs.loginManager.user.firstname}"/>
                    </div>
                    <div>
                        <h:outputLabel styleClass="Float" for="lastname" value="#{msg.lastname}"/>
                        <h:inputText id="lastname" value="#{cc.attrs.loginManager.user.lastname}"/>
                    </div>
                    <div>
                        <h:outputLabel styleClass="Float" for="dateofbirth" value="#{msg.date_of_birth}"/>
                        <h:inputText id="dateofbirth" value="#{cc.attrs.loginManager.user.dateOfBirth}" converterMessage="#{msg.date_format}">
                             <f:convertDateTime type="date" dateStyle="short" />
                        </h:inputText>

                        <h:message for="dateofbirth" styleClass="error"/>
                    </div>
                    <div>
                        <h:outputLabel styleClass="Float" for="sex" value="#{msg.sex}" />
                        <h:selectOneMenu id="sex" value="#{cc.attrs.loginManager.user.sex}">
                            <f:selectItem itemValue="f" itemLabel="#{msg.female}" />
                            <f:selectItem itemValue="m" itemLabel="#{msg.male}" />
                        </h:selectOneMenu>
                    </div>
                </fieldset>
            </div>
            </c:if>

            <c:if test="#{loginManager.needRegister}">
                <h3>#{msg.login_and_stack}</h3>
            </c:if>
                
            <h:outputText styleClass="error" value="#{msg.username_already_exists}" rendered="#{cc.attrs.loginManager.errorOccured}" />
            <div class="formblock">
                <fieldset>
                    <div>
                        <h:outputLabel styleClass="Float" for="username" value="#{msg.username}" rendered="#{cc.attrs.loginManager.needRegister}" />
                        <h:inputText value="#{cc.attrs.loginManager.user.login}" id="username" validatorMessage="#{msg.invalid_username}" rendered="#{cc.attrs.loginManager.needRegister}">
                            <f:validateRegex pattern="^[\p{Alpha}]+$" />
                        </h:inputText>

                        <h:message for="username" styleClass="error"/>
                    </div>

                    <div>
                        <h:outputLabel styleClass="Float" for="password" value="#{msg.password}" rendered="#{cc.attrs.loginManager.needRegister}" />
                        <h:inputSecret id="password" value="#{cc.attrs.loginManager.user.password}" validatorMessage="#{msg.invalid_password}" rendered="#{cc.attrs.loginManager.needRegister}" >
                            <f:validateLength minimum="8"/>
                            <f:validateRegex pattern=".*[\p{Alpha}].*"/>
                            <f:validateRegex pattern=".*[\p{Digit}].*"/>
                        </h:inputSecret>

                        <h:message for="password" styleClass="error"/>
                    </div>

                    <div>
                        <h:outputLabel styleClass="Float" for="stack" value="#{msg.stack_size}" />
                        <h:inputText id="stack" value="#{cc.attrs.loginManager.user.sizeOfStack}" validatorMessage="#{msg.require_4_16_36}">
                            <f:validator validatorId="at.ac.tuwien.ewa.g70.validator.StackValidator" />
                        </h:inputText>
                        <h:message for="stack" styleClass="error"/>
                    </div>
                </fieldset>
            </div>
            <div id="buttons">
                <c:if test="#{loginManager.needRegister}">
                    <h:commandButton id="register" value="#{msg.register}" accesskey="r" action="#{loginManager.registerUser}" />
                </c:if>

                <c:if test="#{loginManager.needRegister == false}">
                    <h:commandButton id="change_userdata" value="#{msg.change_userdata}" accesskey="r" action="#{loginManager.changeUserdata}" />
                </c:if>
            </div>
        </h:form>
  </composite:implementation>
</html>